package com.yami.shop.platform.controller;

import com.yami.shop.bean.dto.FlowAnalysisDto;
import com.yami.shop.bean.dto.SystemDto;
import com.yami.shop.bean.param.FlowAnalysisParam;
import com.yami.shop.common.response.ServerResponseEntity;
import com.yami.shop.service.FlowUserAnalysisExcelService;
import com.yami.shop.service.FlowUserAnalysisService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;


/**
 * @author lgh on 2018/11/26.
 */
@RestController
@RequestMapping("/platform/flowAnalysis")
@Tag(name = "流量概况")
public class FlowAnalysisController {

    @Autowired
    private FlowUserAnalysisService flowUserAnalysisService;

    @Autowired
    private FlowUserAnalysisExcelService flowUserAnalysisExcelService;

    @GetMapping("/getAnalysisData")
    @Operation(summary =  "流量总览", description = "流量总览")
    public ServerResponseEntity<FlowAnalysisDto> getAnalysisData(@ParameterObject FlowAnalysisParam flowAnalysisParam) {
        //获取开始和结束时间
        flowAnalysisParam.setTime(1);
        FlowAnalysisDto flowAnalysisDto = flowUserAnalysisService.getFlowAnalysisData(flowAnalysisParam);
        return ServerResponseEntity.success(flowAnalysisDto);
    }

    @GetMapping("/analysisDataExport")
    @PreAuthorize("@pms.hasPermission('flow:data:export')")
    @Operation(summary =  "导出流量总览", description = "导出流量总览")
    public void analysisDataExport(@ParameterObject FlowAnalysisParam flowAnalysisParam, HttpServletResponse response) {
        //获取开始和结束时间
        flowAnalysisParam.setTime(1);
        flowUserAnalysisExcelService.analysisDataExport(flowAnalysisParam, response);
    }

    @GetMapping("/flowTrend")
    @Operation(summary =  "流量趋势", description = "流量趋势")
    public ServerResponseEntity<List<FlowAnalysisDto>> flowTrend(@ParameterObject FlowAnalysisParam flowAnalysisParam) {
        // 获取开始和结束时间
        flowAnalysisParam.setTime(2);
        List<FlowAnalysisDto> flowAnalysisDtoList = flowUserAnalysisService.flowTrend(flowAnalysisParam);
        return ServerResponseEntity.success(flowAnalysisDtoList);
    }


    @GetMapping("/flowTrendExport")
    @PreAuthorize("@pms.hasPermission('flow:trend:export')")
    @Operation(summary =  "导出流量趋势", description = "导出流量趋势")
    public void flowTrendExport(@ParameterObject FlowAnalysisParam flowAnalysisParam, HttpServletResponse response) {
        //获取开始和结束时间
        flowAnalysisParam.setTime(2);
        flowUserAnalysisExcelService.flowTrendExport(flowAnalysisParam, response);
    }

    @GetMapping("/flowSour")
    @Operation(summary =  "成交转换", description = "成交转换")
    public ServerResponseEntity<List<FlowAnalysisDto>> flowSour(@ParameterObject FlowAnalysisParam flowAnalysisParam) {
        flowAnalysisParam.setTime(1);
        List<FlowAnalysisDto> flowAnalysisDtoList = flowUserAnalysisService.flowSour(flowAnalysisParam);
        return ServerResponseEntity.success(flowAnalysisDtoList);
    }


    @GetMapping("/flowSourExport")
    @PreAuthorize("@pms.hasPermission('flow:sour:export')")
    @Operation(summary =  "导出成交转换", description = "导出成交转换")
    public void flowSourExport(@ParameterObject FlowAnalysisParam flowAnalysisParam, HttpServletResponse response) {
        //获取开始和结束时间
        flowAnalysisParam.setTime(1);
        flowUserAnalysisExcelService.flowSour(flowAnalysisParam, response);
    }

    @GetMapping("/systemTypeNums")
    @Operation(summary =  "系统访客数量", description = "系统访客数量")
    public ServerResponseEntity<SystemDto> systemTypeNums(@ParameterObject FlowAnalysisParam flowAnalysisParam) {
        flowAnalysisParam.setTime(1);
        SystemDto systemDto = flowUserAnalysisService.systemTypeNums(flowAnalysisParam);
        return ServerResponseEntity.success(systemDto);
    }
}
